<?php
include('../../common.php');
if($_SESSION['log_islogin'] == 'yes' ){

	$id = intval(mysql_real_escape_string($_GET['recID']));
	$postcode = intval(mysql_real_escape_string($_GET['postcode']));
	if($id > 0 && strlen($postcode) == 5){
		$qList = "SELECT a.post_office AS city, a.state_code AS state 
					FROM lookup_postcode a  WHERE postcode='$postcode' LIMIT 0,1";
		$rList = $db->sql_list($qList);	

		$city = $rList['city'];
		$state = $rList['state'];
		if(strlen($city) > 0  && strlen($state) > 0 ){
			$sqlUpdReceiverEnt = "UPDATE entity set ent_add_postcode ='$postcode', ent_add_city='$city ', ent_add_state='$state' 
								 WHERE ent_id='$id' ";
			$resUpdReceiverEnt = $db->sql_query($sqlUpdReceiverEnt);
			if($resUpdReceiverEnt)
				echo '1';
			else
				echo '0';
		}else
			echo '0';
	}else
			echo '0';
}else{
	echo 'Dude!';
}
?>